package com.wx.service;

import com.wx.bean.Userbean;
import com.wx.dao.IUserDao;
import com.wx.service.impl.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    IUserDao iUserDao;

    @Override
    public int login(Userbean userbean) {
        String sessionCode=userbean.getSessionCode();
        String code=userbean.getCode();
        Boolean isCode=sessionCode.equals(code);
        if (isCode){
            int result=iUserDao.login(userbean);
            return result;
        }else {
            return 2;
        }
    }

    @Override
    public List<Userbean> findAll() {
        return iUserDao.findAll();
    }

    @Override
    public Userbean findById(Userbean userbean) {
        return iUserDao.findById(userbean);
    }

    @Override
    public List<Userbean> findUserType() {
        return iUserDao.findUserType();
    }

    @Override
    public int update(Userbean userbean) {
        return iUserDao.update(userbean);
    }

    @Override
    public int userAdd(Userbean userbean) {
        int count=iUserDao.findCode(userbean);
        if (count==0){
            int result=iUserDao.userAdd(userbean);
            return result;
        }else {
            return 2;
        }
    }

    @Override
    public int delete(Userbean userbean) {
        return iUserDao.delete(userbean);
    }

    @Override
    public List<Userbean> findCondition(Userbean userbean) {
        return iUserDao.findCondition(userbean);
    }

    @Override
    public int getCount(Userbean userbean) {
        return iUserDao.getCount(userbean);
    }

}
